package com.kedacom.freedomLabel.initdata.dao;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;


import com.kedacom.freedomLabel.initdata.bean.Post;
import com.kedacom.freedomLabel.initdata.bean.Staff;
import com.kedacom.freedomLabel.model.bean.Business;
import com.kedacom.freedomLabel.model.bean.BusinessCount;
import com.kedacom.freedomLabel.model.bean.BusinessGroup;
import com.kedacom.freedomLabel.model.bean.ProductCount;
import com.kedacom.freedomLabel.model.db.dao.IDao;

import java.util.List;


/**
 * Created by yao on 2021/3/23.
 * Describe
 */

@Dao
public interface PostDao extends IDao<Post> {

    @Override
    @Query("SELECT COUNT(0) FROM Post")
    int count();

    @Override
    @Update
    void update(Post data);

    @Override
    @Insert(onConflict = OnConflictStrategy.FAIL)
    long save(Post data);

    @Override
    @Insert(onConflict = OnConflictStrategy.FAIL)
    long[] save(List<Post> data);

    @Override
    @Query("SELECT * FROM Post ORDER BY id")
    List<Post> get();

    @Override
    @Query("SELECT * FROM Post WHERE recordId=:param")
    List<Post> get(String param);


    @Query("SELECT * FROM Post WHERE weighingTime >=:startTime order by weighingTime DESC")
    List<Post> getPostWithStartTime(long startTime);


    @Query("SELECT * FROM Post WHERE  postSuccess = 0 and weighingTime >=:startTime  AND weighingTime<:endTime order by weighingTime DESC")
    List<Post> getThreeDayPost(long startTime,long endTime);


    @Query("SELECT * FROM Post WHERE weighingTime >=:startTime  AND weighingTime<:endTime order by weighingTime DESC")
    List<Post> getOneDayPost(long startTime,long endTime);

    @Query("DELETE FROM Post WHERE weighingTime >=:startTime")
    void deleteWithStartTime(long startTime);


    @Query("DELETE  FROM Post WHERE weighingTime >=:startTime  AND weighingTime<:endTime")
    void deleteOneDayPost(long startTime,long endTime);


    @Query("SELECT COUNT(*) as number,SUM(totalWeight) as weight FROM Post WHERE weighingTime>=:startTime")
    ProductCount getBusiness(long startTime);


    @Override
    @Query("SELECT * FROM Post WHERE recordId=:param1 and recordId LIKE :param2")
    List<Post> get(String param1, String param2);

    @Override
    @Delete
    void delete(Post data);

    @Override
    @Query("DELETE FROM Post")
    void delete();

    @Override
    @Query("DELETE FROM Post WHERE recordId=:param ")
    void delete(String param);


//    @Query("SELECT * FROM Post ORDER BY id desc")
//    List<Post> getAllPost();
//    @Query("SELECT * FROM Post WHERE recordId=:recordId")
//    Post getPostOneById(String recordId);
//    @Insert
//    void insert(Post post);
//    @Insert
//    void insert(List<Post> postes);
//    @Delete
//    void delete(Post post);
//    @Delete
//    void delete(List<Post> userLists);
}